package com.base.controller;


import cn.dev33.satoken.util.SaResult;
import com.base.entity.TestItem;
import com.base.service.ITestItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mockito.internal.stubbing.answers.Returns;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者
 * @since 2024-08-20
 */
@RestController
@RequestMapping("/test-item")
@Api(tags = "测试项目")
@CrossOrigin
public class TestItemController {

    @Autowired
    private ITestItemService testItemService;

    @ApiOperation("测试项目列表")
    @GetMapping("/list")
    public List<TestItem> getList() {
        return testItemService.list();
    }

    @ApiOperation("更新")
    @PostMapping
    public SaResult update(@RequestBody TestItem testItem) {
        if (testItem.getId() == null) {
//            新增
            testItemService.save(testItem);
        } else {
//            编辑
            testItemService.updateById(testItem);
        }
        return SaResult.ok();
    }

    @ApiOperation("移除")
    @GetMapping("/remove/{id}")
    public SaResult remove(@PathVariable Integer id) {
        testItemService.removeById(id);
        return SaResult.ok();
    }

}
